﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace BufaView
{
    public partial class Form1 : Form
    {
		BufaFile _bufaFile;
        public Form1()
        {
            InitializeComponent();
        }

		private void openToolStripMenuItem_Click(object sender, EventArgs e)
		{
			OpenFileDialog ofd = new OpenFileDialog();
			DialogResult ret = ofd.ShowDialog();
			if (ret == DialogResult.OK)
			{
				_bufaFile = new BufaFile(ofd.FileName);
				UpdateListView();
			}
		}

		private void UpdateListView()
		{
			int i = 0;
			listView1.Items.Clear();
			listView1.BeginUpdate();
			foreach (BufaNode node in _bufaFile.Nodes)
			{
				ListViewItem item = new ListViewItem();
				item.Text = i.ToString();
				item.SubItems.Add(node.CreateTime.ToString());
				item.SubItems.Add(node.Length.ToString());
				item.SubItems.Add(node.SequenceNo.ToString());
				item.SubItems.Add(node.ProtocolType.ToString());
				item.SubItems.Add(node.ProtocolData);
				listView1.Items.Add(item);
				i++;
			}
			listView1.EndUpdate();
		}
    }
}
